//
//  XYImageTableViewCell.m
//  十年少
//
//  Created by 尧的mac on 15/11/28.
//  Copyright © 2015年 xxy.icom. All rights reserved.
//

#import "XYImageTableViewCell.h"
#import "XYImageFrom.h"
#import "XYMainModel.h"
#import "UIImageView+WebCache.h"
@interface XYImageTableViewCell ()

@property(nonatomic,weak)UILabel *titleName;
@property(nonatomic,weak)UIView *spcView;
@property(nonatomic,weak)UIView *footView;
@property(nonatomic,weak)UIImageView *image;
@end
@implementation XYImageTableViewCell

+(instancetype)mainCell:(UITableView *)tableView{
    
    XYImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell ==nil) {
        cell = [[XYImageTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        //标题
        UILabel *titleName  =[[UILabel alloc]init];
        titleName.textColor = [UIColor blackColor];
        titleName.font = [UIFont systemFontOfSize:16];
       
        [self.contentView addSubview:titleName];
        self.titleName = titleName;
        
        //分隔线
        UIView *spcView = [[UIView alloc]init];
        spcView.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:spcView];
        self.spcView = spcView;
        
        
        UIImageView * imageView = [[UIImageView alloc]init];
        [self.contentView addSubview:imageView];
        self.image = imageView;
        
        //尾部分割线
        UIView *footView = [[UIView alloc]init];
        footView.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:footView];
        self.footView = footView;
    }
    return self;
}

-(void)setMainModel:(XYImageFrom *)mainModel{
    
    _mainModel = mainModel;
    XYMainModel * main = mainModel.mainModel;
    //标题
    self.titleName.frame = mainModel.titleFrom;
     self.titleName.textAlignment = NSTextAlignmentCenter;
    [self.titleName setText:main.title];
    
    //分隔线
    self.spcView.frame =mainModel.viewFrom;
    
    //图片
    self.image.frame = mainModel.imageFrom;
    
    [self.image setImageWithURL:[NSURL URLWithString:main.img] placeholderImage:[UIImage imageNamed:@"【20150806】 (1)"]];
}



@end
